//index.js
//获取应用实例
const app = getApp()

Page({
  data: {
    motto: 'Hello World',
    userInfo: {},
    hasUserInfo: false,
    canIUse: wx.canIUse('button.open-type.getUserInfo'),
    
    indicatorDots: true,
    autoplay: true,
    interval: 2000,
    duration: 500,
    imgUrls: [
      '/images/index/1508084278.jpg',
      '/images/index/1559970047.jpg',
      '/images/index/434876515.jpg',
      '/images/index/1959491283.jpg'
    ],
    envUrl:[
      '/images/index/1915271435.jpg',
    ],
    bussiness:[
      [
        {
          "id":1,
          "imgUrl": "/images/index/dailjizhang.png",
          "name":"代理记账"
        },
        {
          "id": 2,
          "imgUrl": "/images/index/company.png",
          // "name": "工商代理"
          "name":"公司注册"
        },
        {
          "id": 3,
          "imgUrl": "/images/index/zhuce.png",
          "name": "商标专利"
        }
      ],
      [
        {
          "id": 4,
          "imgUrl": "/images/index/nianjian.png",
          //"name": "年报年检"
          "name": "入住电商"
        },
        {
          "id": 5,
          "imgUrl": "/images/index/biangeng.png",
          "name": "公司购买"
        },
        {
          "id": 6,
          "imgUrl": "/images/index/internet.png",
          "name": "互联网资质"
        },
      ],
      [
        {
          "id": 7,
          "imgUrl": "/images/index/address.png",
          "name": "地址挂靠"
        },
        {
          "id": 8,
          "imgUrl": "/images/index/bonus.png",
          //"name": "许可资质"
          "name": "补贴入户"
        },
        {
          "id": 9,
          "imgUrl": "/images/index/zizhi.png",
          //"name": "税务筹划"
          "name": "许可资质"
        }
      ],
    ],
  },
  //事件处理函数
  bindViewTap: function() {
    wx.navigateTo({
      url: '../logs/logs'
    })
  },
  onShareAppMessage: function () {
    return {
      title: '一米企业 - 首页',
    }
  },
  onLoad: function () {
    this.setData({
      wxID: app.globalData.wxID,
      phoneNum: app.globalData.phoneNum,
    })
    
    if (app.globalData.userInfo) {
      this.setData({
        userInfo: app.globalData.userInfo,
        hasUserInfo: true,
      })
    } else if (this.data.canIUse){
      // 由于 getUserInfo 是网络请求，可能会在 Page.onLoad 之后才返回
      // 所以此处加入 callback 以防止这种情况
      app.userInfoReadyCallback = res => {
        this.setData({
          userInfo: res.userInfo,
          hasUserInfo: true
        })
      }
    } else {
      // 在没有 open-type=getUserInfo 版本的兼容处理
      wx.getUserInfo({
        success: res => {
          app.globalData.userInfo = res.userInfo
          this.setData({
            userInfo: res.userInfo,
            hasUserInfo: true
          })
        }
      })
    }
  },
  getUserInfo: function(e) {
    console.log(e)
    app.globalData.userInfo = e.detail.userInfo
    this.setData({
      userInfo: e.detail.userInfo,
      hasUserInfo: true
    })
  },
  phonecall:function(){
    wx.showActionSheet({
      itemList: ['拨打电话', '复制微信号'],
      success: function (res) {
        console.log(res.tapIndex)
        if (0 == res.tapIndex){
          wx.makePhoneCall({
            phoneNumber: app.globalData.phoneNum,
          })
        }else{
          wx.setClipboardData({
            data: app.globalData.wxID,
            success: function (res) {
              wx.showToast({
                title: '复制成功',
                icon: 'success',
                duration: 1000
              })
              wx.getClipboardData({
                success: function (res) {
                  console.log(res.data) // data
                }
              })
            }
          })
        }
      },
      fail: function (res) {
        console.log(res.errMsg)
      }
    })
    
  },
  onJumpTo:function(e){
    console.log(e.currentTarget.id)
    wx.navigateTo({
      url: '../service-detail/service?id=' + e.currentTarget.id
    })
  },
})
